<?php


namespace app\api\controller;


use think\facade\Log;

class Wechat extends Base
{
    protected static $token = '52zsj';

    public function verify()
    {
        $params = $this->request->param();

        $signature = $params["signature"];
        $timestamp = $params["timestamp"];
        $nonce = $params["nonce"];
        $tmpArr = [self::$token, $timestamp, $nonce];
        sort($tmpArr, SORT_STRING);
        $tmpStr = implode($tmpArr);
        $tmpStr = sha1($tmpStr);
        $echostr = $params['echostr'];
        Log::write('请求信息：'.json_encode($params).'生成内容:'.$tmpStr,'debug');
        if ($tmpStr == $signature) {
            return $echostr;
        } else {
            return false;
        }
    }
}
